import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/login'
import Home from '@/views/home'
import Detail from '@/views/home/detail.vue'
import Depart from '@/views/department'

// 导入公共布局组件
import Layout from '@/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  // 路由的模块化配置
  // 首页=>相关页面都在这里配置
  {
    path: '/home',
    // 父：公共布局组件
    component: Layout,
    children: [
      // 子：基于公共布局渲染的页面
      // 首页
      {
        path: '',
        component: Home
      },
      // 其它页面=》详情页
      {
        path: '/home/detail/:id',
        component: Detail
      }
    ]
  },
  {
    path: '/department',
    // 父：公共布局组件
    component: Layout,
    children: [
      // 子：基于公共布局渲染的页面
      {
        path: '',
        component: Depart
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
